import SmCrypto from 'sm-crypto';

// 后端提供的公钥
const publicKey =
  '';

// 编码模式，默认为1，此处设置为0
const cipherMode = 0;

/**
 *
 * @param {*} plaintext 需要加密的字符
 * @returns 需要带上04
 */
const SM2_Encrypt = plaintext => {
  const ciphertext = SmCrypto.sm2.doEncrypt(plaintext, publicKey, cipherMode).toString();
  return `04${ciphertext}`;
};

export default SM2_Encrypt;
